<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>移动</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/plugin/it/common/css/demo.css" type="text/css">
    <link rel="stylesheet" href="/plugin/it/common/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body style="background-color: #fff">
<div class="layui-row" style="margin-left:20px;margin-top:20px"><span style="font-size:22px"><strong id="title">移动</strong></span></div>
<div class="layui-container ztree" style="padding: 10px 20px 80px 20px">
        <div>
            <ul id="treeDemo"></ul>
        </div>
</div>
<div class="layui-footer" style="width: 100%;text-align: center;background-color: #fff;position:fixed;bottom:0px;height: 50px;padding-top: 15px">
    <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="_itkl.content.layerClose()">关闭</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="moveAction()">确定</button>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js"></script>
<!--JQ-->
<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugin/it/common/js/itkl.js"></script>
<script type="text/javascript" src="/plugin/it/common/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/plugin/it/common/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<SCRIPT type="text/javascript">
    var actionType = localStorage.getItem("movepageactiontype");
    //关于actionType:
    //actionType代表了打开树页面的来源
    //当actionType为空或未设置时,代表的是移动文件操作
    //当actionType为2时,代表的是管理后台页面设置文件夹属性操作
    localStorage.removeItem("movepageactiontype");
    var chkStyleStr = "radio";

    var setting = {
        check: {
            enable: true,
            chkStyle: "radio",
            radioType: "all"
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    //需要多选的页面设置为checkbox
    if("2" == actionType){
        //开启多选
        setting.check.chkStyle = "checkbox";
        //点击某节点没有关联操作
        setting.check.chkboxType = { "Y": "", "N": "" };
    }

    var _zTree = $.fn.zTree;
    $(document).ready(function(){
        var getDataUrl = '/it/dic/getAllDic';
        //设置页面标题
        if(actionType && actionType == '2'){
            $('#title').html('选择文件夹');
        }
        if(!actionType || actionType == '3'){
            //只获取设置为一级目录相关的
            getDataUrl = '/it/dic/getAllDicSeted';
        }

        //获取所有的目录：
        $.ajax({
            url: getDataUrl,
            type: 'get',
            dataType: 'json',
            success: function(res){
                if(res){
                    _zTree.init($("#treeDemo"), setting, res);
                }else{
                    layer.msg('获取数据失败',{icon:2});
                    return ;
                }
            }
        })

    });

    //点击树页面确定按钮的操作
    //根据不同的功能来源执行不同的操作

    function moveAction(){
        var treeObj = _zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
        if(!nodes || nodes.length == 0){
            parent.layer.msg("请先选中目标文件夹",{icon:2});
            return ;
        }
        var targetFileId = nodes[0].id;
        var targetFileName = nodes[0].name;
        if(actionType && actionType == '2'){
            //设置IT表单页面,获取编号:
            localStorage.setItem("checkeddicnodes",JSON.stringify(nodes));
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            return ;
        }else if(actionType && actionType == '3'){
            localStorage.setItem("checkeditformfileid",targetFileId);
            localStorage.setItem("checkeditformfilename",targetFileName);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            return ;
        }

        if(nodes && nodes.length>0){
            var sourceFileType = localStorage.getItem('movefromzskfiletype');
            var sourceFileId = localStorage.getItem('movefromfileid');
            var sourceFileName = localStorage.getItem('movefromfilename');
            layer.confirm('确定将'+sourceFileType+' <strong>'+sourceFileName+'</strong> 移动到文件夹 <strong>'+targetFileName+'</strong> 下吗？', function(index){
                _itkl.file.move(sourceFileId,targetFileId);
                layer.close(index);
            });
        }else{
            layer.msg("请选择移动目标文件夹",{icon:2});
            return ;
        }


    }
</SCRIPT>
</body>
</html>